#!/bin/sh
# postrm script for svnyoungest
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postrm> `remove'
#        * <postrm> `purge'
#        * <old-postrm> `upgrade' <new-version>
#        * <new-postrm> `failed-upgrade' <old-version>
#        * <new-postrm> `abort-install'
#        * <new-postrm> `abort-install' <old-version>
#        * <new-postrm> `abort-upgrade' <old-version>
#        * <disappearer's-postrm> `disappear' <overwriter>
#          <overwriter-version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

package=playsms
webserver=apache2
webuser=www-data
installpath=/usr/share/$package
binpath=$installpath/bin
dbinfo=/etc/$package/dbinfo.php

# start up debconf and dbconf-common
if [ -f /usr/share/debconf/confmodule ]; then
    . /usr/share/debconf/confmodule
fi
if [ -f /usr/share/dbconfig-common/dpkg/postrm.mysql ]; then
    . /usr/share/dbconfig-common/dpkg/postrm.mysql
    dbc_go $package $@
fi

if [ "$1" = "remove" ] || [ "$1" = "purge" ]; then
     # revoke the sudo rights for the webuser
     # by finding the line we added to sudoers 
     # and removing it
     #
     sedscript="s_$webuser.*$binpath.*__"
     sed -i -e $sedscript /etc/sudoers


     # restore the original kannel confs
     #

     kannelconf=/etc/kannel/kannel.conf
     if [ -e $kannelconf.1 ]; then
        mv $kannelconf.1 $kannelconf || true
     fi
     kanneldefaults=/etc/default/kannel
     if [ -e $kanneldefaults.1 ]; then
        mv $kanneldefaults.1 $kanneldefaults || true
     fi


     # reload services whose confs have been modified
     #
     logger "restarting apache and kannel..."
     if [ -x /usr/sbin/invoke-rc.d ]; then
          invoke-rc.d $webserver reload || true
          invoke-rc.d kannel restart || true
     else
          /etc/init.d/$webserver reload || true
          /etc/init.d/kannel restart || true
     fi   
fi

if [ "$1" = "purge" ]; then
	rm -f $dbinfo
	if which ucf >/dev/null 2>&1; then
		ucf --purge $dbinfo
	fi
fi


# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0


